import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { FactoryEquip, FactoryClassType } from "@/api/backend/index";
import qs from "qs";

export const useFactoryEquipment = defineStore(Names.factoryE, {
  state: () => {
    return {
      id: 0,
      single: { id: 0, equipmentCode: "" },
      stationInfo: {},
    };
  },
  getters: {},
  actions: {
    //设备单元导入excel文件
    importExcel(data: any) {
      return new Promise((resolve, reject) => {
        _post(FactoryEquip + "/import", data, "formData", "")
          .then((res) => {
            console.log("导入excel文件", res);
            resolve(res as any);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    //获取设备数据
    getEquipmentByRole(filter: any) {
      return new Promise((resolve, reject) => {
        _get(
          FactoryEquip +
            "/list?" +
            qs.stringify(filter, { arrayFormat: "repeat" }),
          {},
          "json",
          ""
        )
          .then(async (res: any) => {
            resolve(res.rows);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    //设备排班
    scheduling(filter: any) {},
  },
});
